class TravelguideController < ApplicationController
  
  def test
    
  end
  
  scaffold :category
  
  def test
    
  end
  
  def index        
    @allecountries = Country.find :all
  end
  
 def showcountry
    @country = Country.find_by_id params[:id]
    @citiescountry = City.find :all, :conditions => { :country_id => params[:id]}
    
  end
  
  def newcountry
    @allecountries = Country.find :all 
  end
  
  def create_country
    @new_country = Country.new(params[:country]) 
    @new_country.save
    
    
    redirect_to :action => :showcountry, :id => @new_country.id
  end


 def showcity
    @city = City.find_by_id params[:id]
    @country = Country.find_by_id params[:country_id]
    @locations_city = Location.find :all, :conditions => { :city_id => params[:id]}
    @allcategories = Category.find :all
  end

   def newcity    
    @country = Country.find params[:country_id]
    @citiescountry = City.find :all, :conditions => { :country_id => params[:country_id]}
  end
   
   def create_city
    @new_city = City.new(params[:city]) 
    @new_city.save
    
    redirect_to :action => :showcity, :id => @new_city.id
  end
  
  def showlocation
    @location = Location.find_by_id params[:id]
    @category = Category.find_by_id params[:category_id]
    @city = City.find_by_id params[:city_id]
    @country = Country.find_by_id params[:country_id]

  end
  
  def newlocation    
    @city = City.find params[:city_id]
    @allecategories = Category.find :all
    @country = Country.find_by_id params[:country_id]
    @locations_city = Location.find :all, :conditions => { :city_id => params[:city_id]}
  end
  
  def create_location
    @new_location = Location.new(params[:location]) 
    @new_location.save
    
    redirect_to :action => :showlocation, :id => @new_location.id
  end
  
  def showcategory
    @allcategories = Category.find :all
    @locations_categories_city = Location.find :all, :conditions => { :category_id => params[:id], :city_id => params[:city_id]}
    @category = Category.find_by_id params[:id]
    @city = City.find_by_id params[:city_id]
    @country = Country.find_by_id params[:country_id]


  end
  
  def newcategory
    @allcategories = Category.find :all
    @city = City.find_by_id params[:city_id]
    @country = Country.find_by_id params[:country_id]
  end
  
  def create_category
    @new_category = Category.new(params[:category]) 
    @new_category.save
    
    redirect_to :action => :index
  end
end
